home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cuj9205.zip / CMENU13.EXE / RCMENU.H < prev    next >
C/C++ Source or Header  |  1992-04-22  |  6KB  |  225 lines

  1. /************************************************************
  2.  *    Program: RMENU Menu Interpreter
  3.  *  Module: rcmenu.h -- Interpreter Module header file
  4.  *    Written by: Leor Zolman, 7/91
  5.  ************************************************************/
  6.  
  7. #include <curses.h>
  8.  
  9. #define min(x,y) ((x) < (y) ? (x) : (y))
  10.  
  11.  
  12. /********************* Curses Configuration *****************/
  13.  
  14. #ifndef KEY_UP
  15. #    define    OLD_CURSES 1        /* no KEY_UP definition: old Curses */
  16. #else
  17. #    define    OLD_CURSES 0        /* KEY_UP defined: new Curses        */
  18. #endif
  19.  
  20. #if OLD_CURSES                    /* under old Curses, emulate some    */
  21. #    define    INIT_FAIL    ERR        /* of new Curses' features            */
  22. #    ifdef CTRL
  23. #        undef CTRL
  24. #    endif
  25. #    define CTRL(x)        ((x) & 037)
  26. #    define    KEY_UP        CTRL('P')
  27. #    define    KEY_DOWN    CTRL('N')
  28. #    define    KEY_LEFT    CTRL('B')
  29. #    define    KEY_RIGHT    CTRL('F')
  30. #    define    beep()        write(1, "\007", 1);
  31. #    define    keypad(a,b)
  32. #else
  33. #    define    INIT_FAIL    NULL
  34. #endif 
  35.  
  36. #if XENIX
  37. #define    resetty reset_tty
  38. #endif
  39.  
  40. #if DOS                                        /* Color definitions for DOS:    */
  41. #define    DOS_FCOLOR    A_CYAN                    /* Normal DOS foreground color    */
  42. #define    DOS_BCOLOR    A_BLACK                    /* Normal DOS background color    */
  43.  
  44. #define M_FCOLOR    A_YELLOW                /* Normal Menu foregnound color    */
  45. #define M_BCOLOR    A_BLUE                    /* Normal Menu background color    */
  46.  
  47. #define    MREV_FCOLOR    A_BLUE                    /* Reverse Menu foregnd color    */
  48. #define    MREV_BCOLOR    A_WHITE                    /* Reverse Menu backgnd color    */
  49. #endif
  50.  
  51.  
  52. /*************** Default menu control options ***************/
  53.  
  54. #define    ON_ERROR        50        /* prompt option            */
  55.  
  56. #define    SHELL_PROMPT    FALSE    /* Prompt for shell escape? */
  57.  
  58. #define DEF_PRECLEAR    YES
  59. #define    DEF_POSTCLEAR    NO
  60. #define DEF_PROMPT        ON_ERROR  /*  YES, NO or ON_ERROR    */
  61. #define    DEF_ESCAPE        YES
  62.  
  63. #define    DEF_COLUMNS        1
  64. #define    DEF_SPACING        2
  65.  
  66.  
  67. /************** Screen layout characteristics ***************/
  68.  
  69. #define MAX_IROWS    18        /* # of item rows MUST BE EVEN) */
  70. #define    HOME_Y        2        /* upper left y for 1st Item    */
  71. #define HOME_X        1        /* upper left x for 1st Item    */
  72. #define    SCREEN_COLS    80        /* # of columns on the screen    */
  73.  
  74. #define TITLE_ROW    0        /* row on screen for menu title    */
  75. #define HELP_ROW0    20        /* row that "HELP" sign goes on    */
  76. #define    HELP_COL0    36        /* column that "HELP" sign goes    */
  77. #define HELP_ROW    21        /* row on screen for HELP text    */
  78. #define PROMPT_ROW    23        /* row for prompt text            */
  79.  
  80.  
  81. /** System/hardware-dependent Key codes and line numbers: ***/
  82.  
  83. #if DOS
  84. #    define LAST_ROW       24    /* last row of screen        */
  85. #    define MAX_PATH_STACK 5        /* maximum nested submenus    */
  86. #else
  87. #    define LAST_ROW     23        /* last row of screen        */
  88. #endif
  89.  
  90. #define ERR_ROW        (PROMPT_ROW - 1)
  91.  
  92.  
  93. /************** Shell Escape Control Parameters *************/
  94.  
  95. #define    SH_PROMPT_STR \
  96.     " Press Enter for sub-shell, ESC to abort\
  97.  ('exit' returns from shell): "
  98.  
  99. #define    MENU_OPTS \
  100.  " Space/arrows/item#=Choose  ENTER=Run\
  101.   'e'=Previous  'x'=Exit "
  102.  
  103. #define MENU_SHELL    " !=shell "
  104. #define MENU_PROMPT " -> "
  105.  
  106. #ifndef DOS
  107. #    define SHELL_ESC    "PS1=\"\n('exit' returns to\
  108.  Menu)\n$ \"; export PS1; exec sh -"
  109. #endif
  110.  
  111.  
  112. /********** Other Miscellaneous constants: *****************/
  113.  
  114. #define ESC            033        /* ESC key                        */
  115. #define EXITALL        2        /* "super exit" code            */
  116.  
  117. #define KEY_RUN        '\r'    /* raw-mode Enter key        */
  118. #define    KEY_SHOW    'a'        /* show action text    for an item    */
  119. #define K_DIRECT    (-2)    /* values returned by get_cmd()    */
  120. #define    K_EXIT        (-3)
  121. #define    K_EXITALL    (-4)
  122. #define    K_SHELL        (-5)
  123. #define    K_UNKNOWN    (-6)
  124. #define    K_VERSION    (-7)    /* report version number        */
  125.  
  126. #define    STANDOUT    1        /* video mode codes passed to    */
  127. #define    NORMAL        2        /* the draw_item() function        */
  128.  
  129.  
  130. /********************* Global data **************************/
  131.  
  132. extern struct levels {
  133.     int n_menus;                /* # currently active    */
  134.     int max_menus;                /* highest ever active    */
  135.     struct menu2 {
  136.         int most_items;            /* most Items allocated    */
  137.         MENU Menu;                /* the header structure    */
  138.         ITEM *Items[MAX_ITEMS];    /* the actual items        */
  139.  
  140.         int field_len;            /* length of item field    */
  141.         struct coord {            /* coords of each item    */
  142.             int ypos, xpos;
  143.             int spaces_needed;    /* # of spaces to fill    */
  144.         } coords[MAX_ITEMS];
  145.  
  146.     } *Menus[MAX_MENUS];
  147. } LMenus[MAX_NEST];
  148.  
  149. typedef struct levels LEVELS;
  150. typedef struct menu2 MENU2;
  151. typedef struct coord COORDS;
  152.  
  153. extern    int        nestlev;        /* current nesting level        */
  154. extern    int        echox, echoy;    /* Location of item # echo area */
  155. extern    int        debug;            /* true to display sys commands    */
  156.  
  157. extern    char    SysShell[80];    /* System Command Interpreter    */
  158.  
  159. /********************* Prototypes: **************************/
  160.  
  161. #if __STDC__ || XENIX        /* Standard C, supporting prototypes: */
  162.  
  163. void    init_win(void);
  164. void    close_win(void);
  165. void    pre_shell(void);
  166. void    post_shell(void);
  167. void    tty_curses(void);
  168. void    tty_shell(void);
  169. void    push_path(void);
  170. void    pop_path(void);
  171.  
  172. int     ld_menu(char *);
  173. void    placement(MENU *);
  174. void    free_menus(void);
  175. int        do_menu(char *, char *);
  176. int        sub_menu(int, char *);
  177. void    draw_menu(MENU2 *, int);
  178. int        get_cmd(int, int, int *);
  179. int        put_msg(int, char *, ...);
  180. int        do_item(MENU2 *, int, char *);
  181. void    draw_item(MENU2 *, int, int, int);
  182. int     fatal(char *, ...);
  183. void    do_cmnd(ITEM *, char *);
  184. int        do_emenu(ITEM *, char *);
  185. int        system0(char *);
  186. char *    make_path( char *, char *);
  187. char *    make_cmd( char *, char *);
  188. void    show_item(MENU2 *, int, char *);
  189. void     show_cmnd(ITEM *, char *);
  190. void    hlight_on(void);
  191. void    hlight_end(void);
  192.  
  193. #else        /* K&R C, minimal "prototypes:" */
  194.  
  195. int        init_win();
  196. int        close_win();
  197. int        pre_shell();
  198. int        post_shell();
  199. int        tty_curses();
  200. int        tty_shell();
  201. int        push_path();
  202. int        pop_path();
  203.  
  204. int     ld_menu();
  205. int        placement();
  206. int        free_menus();
  207. int        do_menu();
  208. int        sub_menu();
  209. int        draw_menu();
  210. int        get_cmd();
  211. int        put_msg();
  212. int        do_item();
  213. int        draw_item();
  214. int     fatal();
  215. int        do_cmnd();
  216. int        do_emenu();
  217. int        system0();
  218. char *    make_path();
  219. char *    make_cmd();
  220. int        show_item();
  221. int     show_cmnd();
  222. int        hlight_on();
  223. int        hlight_end();
  224. #endif
  225.